﻿
//获取传递的参数
var Request = {
    QueryString: function (item) {
        var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i"));
        return svalue ? svalue[1] : svalue;
    }
}
//自定义扩展
jQuery.extend({
    //根据serializeArray，返回一个另外的json
    serializeMVC: function (serializeArray) {
        var strJson = "{";
        $.each(serializeArray, function (obj) {
            strJson += this.name + ":";
            strJson += "'";
            var arr1 = this.value.split("'");
            var value = "";
            for (var i = 0; i < arr1.length; i++) {
                if (i > 0) {
                    value += "\\'";
                }
                value += arr1[i];

            }

            var arr2 = value.split("\n");
            value = "";
            for (var i = 0; i < arr2.length; i++) {
                if (i > 0) {
                    value += "\\n";
                }
                value += arr2[i];

            }

            strJson += value + "',";
        });
        strJson += "}";
        strJson = strJson.replace(",}", "}");
        return eval('(' + strJson + ')');
    }
})

//**********************************************************提示信息****************************************************//

//**********************************************************提示信息****************************************************//

//显示读取数据时的提示信息
function showAscyGetData(msg) {

    var wrap = $("body");
    $("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: wrap.width(), height: wrap.height() }).appendTo(wrap);
    if (msg == "") {
        $("<div class=\"datagrid-mask-msg\"></div>").html("数据加载中请等一下咯……").appendTo(wrap).css({ display: "block", left: (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2, top: (wrap.height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2 });
    }
    else {
        $("<div class=\"datagrid-mask-msg\"></div>").html(msg).appendTo(wrap).css({ display: "block", left: (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2, top: (wrap.height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2 });
    }
}
//显示读取数据时的提示信息
function showAscyGetData_obj(obj, msg) {
    //$(obj).append($("<div>"+msg+"</div>").addClass("ascysubmitMsg"));
    var wrap = $(obj);
    $("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: wrap.width(), height: wrap.height() }).appendTo(wrap);
    if (msg == "") {
        $("<div class=\"datagrid-mask-msg\"></div>").html("数据加载中请等一下咯……").appendTo(wrap).css({ display: "block", left: (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2, top: (wrap.height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2 });
    }
    else {
        $("<div class=\"datagrid-mask-msg\"></div>").html(msg).appendTo(wrap).css({ display: "block", left: (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2, top: (wrap.height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2 });
    }
}
//隐藏读取数据时的提示信息
function hideAscyGetData(msg) {
    var wrap = $(obj);
    $("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: wrap.width(), height: wrap.height() }).appendTo(wrap);
    if (msg == "") {
        $("<div class=\"datagrid-mask-msg\"></div>").html("数据加载中请等一下咯……").appendTo(wrap).css({ display: "block", left: (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2, top: (wrap.height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2 });
    }
    else {
        $("<div class=\"datagrid-mask-msg\"></div>").html(msg).appendTo(wrap).css({ display: "block", left: (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2, top: (wrap.height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2 });
    }
}
//显示设置数据时的提示信息
function showAscySetData(msg) {
    var wrap = $("body");
    $("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: wrap.width(), height: wrap.height() }).appendTo(wrap);
    if (msg == "") {
        $("<div class=\"datagrid-mask-msg\"></div>").html("数据加载中请等一下咯……").appendTo(wrap).css({ display: "block", left: (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2, top: (wrap.height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2 });
    }
    else {
        $("<div class=\"datagrid-mask-msg\"></div>").html(msg).appendTo(wrap).css({ display: "block", left: (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2, top: (wrap.height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2 });
    }
}
//隐藏设置数据时的提示信息
function hideAscySetData(msg) {
    $(".datagrid-mask").remove();
    $(".datagrid-mask-msg").remove();
}
//**********************************************************提示信息end****************************************************//
//**********************************************************提示信息end****************************************************//


//**********************************************************其它****************************************************//
//异步请求时的超时跳转
function CS00(_value) {
    if (_value.indexOf("CS00") > -1) {
        if (_value.substring(0, 4) == "CS00") {
            return true;
        }
    }
    return false;
}
//异步请求时的超时跳转
function CheckCS00(_value) {
    if (_value.indexOf("CS00") > -1) {
        if (_value.substring(0, 4) == "CS00") {
            if (window.parent != null) {
                window.parent.location.href = "/Account/LogOn"; 
            }
            else {
                window.location.href = "/Account/LogOn";
            }
            return false;
        }
    }
}
//**********************************************************其它end****************************************************//


//组得到交点的文本框加样式
$(document).ready(function () {
    $(":text").focus(function () {
        $(this).addClass("txt_focus");
    })
    $(":text").blur(function () {
        $(this).removeClass("txt_focus");
    });
    //跳转页回车
    $(document).on('keydown', '#MyPage', function (event) {
        if (event.keyCode == 13) {
            $("#PageIndex").val($("#MyPage").val());
     
            $("#btnSearch").click();
            return false;
        }
    });
    //回车搜索功能
    $(window).keydown(function (event) {
        if (event.keyCode == 13) {
            $("#btnSearch").click();
            return false;
        }
    });
});

//*********************************************

//*************分页提交，和查询条件的传输
function PageLink(_url, _from) {
    showAscySetData('数据请求中，请等待……');
    $.ajax({
        type: "Post",
        url: _url + "?time=" + new Date().getTime(),
        data: $.serializeMVC($(_from).serializeArray()),
        success: function (msg) {
            CheckCS00(msg); //超时判断
            $("#List").html(msg);
        },
        complete: function (msg) {
            AddTableStyle(".List"); //给表格加样式
            hideAscySetData();
        }

    });
}
function PageLink2(_url, page,_from) {
    showAscySetData('数据请求中，请等待……');
    $("#PageIndex").val(page);
    $.ajax({
        type: "Post",
        url: _url + "?time=" + new Date().getTime(),
        data: $.serializeMVC($(_from).serializeArray()),
        success: function (msg) {
            CheckCS00(msg); //超时判断
            $("#List").html(msg);
        },
        complete: function (msg) {
            AddTableStyle(".List"); //给表格加样式
            hideAscySetData();
        }

    });
}
function PageLinkx(_url, _from, _divName) {
    showAscySetData('数据请求中，请等待……');
    $.ajax({
        type: "Post",
        url: _url + "&time=" + new Date().getTime(),
        data: $.serializeMVC($(_from).serializeArray()),
        success: function (msg) {
            CheckCS00(msg); //超时判断
            $(_divName).html(msg);
        },
        complete: function (msg) {
            AddTableStyle(".List"); //给表格加样式
            hideAscySetData();
        }

    });
}
//给表格加样式
function AddTableStyle(_DivList) {
    //奇行样式
    $(_DivList + " tr:odd").addClass("odd");
    //偶数行样式
    $(_DivList + " tr:even").addClass("even");
    //选中样式 用了这个，既然选中框就选不中了
    //$(_DivList + " tr").toggle(function () { $(this).addClass("selected"); }, function () { $(this).removeClass("selected"); });
    $(_DivList + " tr").click(function () {
        if ($(this).attr("class").indexOf("selected") > -1) {
            $(this).removeClass("selected");
        }
        else {
            $(this).addClass("selected");
        }
    });
   $("table th").resize({});
}
//获取表格中的选中值
function getListCheckbox(_DivList) {
    var str_select="";
    $(_DivList + " input:checked").each(function (index, item) {

        if ($(item).val() != "-1") {
            str_select += item.value + ",";
        }

    });
    if (str_select.indexOf(",") > -1) {
        str_select = str_select.substring(0, str_select.length-1);
    }
    return str_select;
}
//注册列表中的全选事件
function registerCheckClick(_select) {
    $(document).on('click', _select + " input:checkbox", function () {
        if ($(this).val() == "-1") {
            if ($(this).attr("checked")) {

                $(_select + " input:checkbox").attr("checked", "true");
            }
            else {
                $(_select + " input:checkbox").removeAttr("checked");
            }
        }
    });
}
//返回上一页
function back() {
    history.go(-1); 
}
//***********************************初始化所有先加载信息**********//*********************************************/
$(document).ready(function () {
    AddTableStyle(".List"); //给表格加样式
});

//***********************************弹出层处理star**********//*********************************************/
//*******************
//**说明：功能需要在主页加两个div
//**    <div id="page">
//**    </div>
//**    <div id="Temppage">
//**    </div>
//**一个代表第二次还需要。一个表示临时用
//*******************
//临时弹出---没有父级，就在当前弹出，有就在父级弹出
var $Tempwin;
function PopupParent(_title, _href, _width, _height) {
    var $Temppage = $("#Temppage");
    //你还是有父页呢！
    $Temppage.html("");
    $(".window,.window-shadow,.windoww-mask").remove();
    $Temppage.append("<div id='Tempwin'>");
    $Tempwin=$("#Tempwin").window({
        title: _title,
        href: _href,
        width: _width,
        modal: true,
        shadow: true,
        height: _height
    });

}
function PopupParentClose() {
    $Tempwin.window('close');
    
}
//***********************************弹出层处理end**********//*********************************************/

//提示信息
//--iconfClass:span_info,span_error,span_warning
function alertMsg(Msg,iconClass) {
    var $selector = $("#selector");
    if ($selector.length==0) {
        $selector = $("<div>").attr("id", "selector");
    }
    var span = "<span class='"+iconClass+"'/>";
    $selector.html(span + Msg);
    $selector.dialog({
        modal: true,
        buttons: [
					{
						text: "确定",
						click: function () { $(this).dialog("close"); }
					}
				]
    });

}
//询问确定信息
//--提示内容，点确定触发事件
function confirmMsg(Msg, funcSuccess) {
    var $selector = $("#selector");
    if ($selector.length == 0) {
        $selector = $("<div>").attr("id", "selector");
    }
    var span = "<span class='span_confirm'/>";
    $selector.html(span + Msg);
    $selector.dialog({
        modal: true,
        buttons: [
					{
					    text: "确定",
					    click: function () { $(this).dialog("close"); funcSuccess; }
					},
                    {
                        text: "取消",
                        click: function () { $(this).dialog("close"); }
                    }
				]
    });
}
function ss() {
    var top = 36;
    var left = 26;
    if ($.support.version == "6.0") {
        $("#c_sub").css({ height: $(window.parent.document).height() - (top + 145), width: $(document).width() - (left + 2) });
        $(".Left").css({ height: $(document).height() - (top+20) });

    } else if ($.support.mozilla) {

        $("#c_sub").css({ height: $(window.parent.document).height() - (top + 145), width: $(document).width() - (left + 2) });
        $(".Left").css({ height: $(document).height() - (top + 20) });

    } else {

        //$("#c_sub").css({ height: $(document).height() - (top), width: $(document).width() - (left + 2) });
        $("#c_sub").css({ height: $(window.parent.document).height() - (top + 93), width: $(document).width() - (left) });
        $(".Left").css({ height: $(document).height() - (top + 20) });

    }
}

$(function () {
    ss();
})


function alertshow(_msg, _callbackUrl) {
    if (_callbackUrl == "") {
        $.messager.alert('提示信息', _msg, "info")
        return false;
    }
    $.messager.confirm('提示信息', _msg, function (r) {
        if (r) {
            window.location.href = _callbackUrl;
            return false;
        }
    });
}
